package com.zsd.android.opengldemo.handler;

import com.zsd.android.opengldemo.interfaces.DBHelper;
import com.zsd.android.opengldemo.utils.MLog;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DBHandler implements InvocationHandler {

    private DBHelper dbHelper;

    public DBHandler(DBHelper dbHelper) {
        this.dbHelper = dbHelper;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (dbHelper != null) {
            String methodName = method.getName();
            MLog.i("methodName = " + methodName);
            if (!"save".equals(methodName)) {
                dbHelper.save();
            }
            return method.invoke(dbHelper, args);
        }
        return null;
    }
}
